package service.network;

import materials.network.*;
import materials.neurons.*;

/**
 * A Service, which contains a lot of Operation, that can be used on a
 * "Neuronal Network"
 * 
 * @author Sheepy
 */
public class NetworkManageService {

	/**
	 * Network the Operation are used to
	 */
	NetworkInterface _neuronalnet;

	/**
	 * Creates a new Service which a Reference to a Network
	 * 
	 * @param nni
	 */
	public NetworkManageService(NetworkInterface nni) {
		_neuronalnet = nni;
	}

	/**
	 * Returns the Current Network
	 * 
	 * @return
	 */
	public NetworkInterface getCurrentNetwork() {
		return (NetworkInterface) _neuronalnet;
	}


	/**
	 * Creates a new Layer and adds it to the current Network
	 * 
	 * @param i - the LayerNumber which should be created
	 */
	public void createNewNetworkLayer() {
		assert _neuronalnet != null : "Vorbedingung verletzt: _neuronalnet != null";
		_neuronalnet.raiseLayer();
	}

	/**
	 * Connects two Neurons if: - the Network != null - the first Neuron nmia -
	 * the second Neuron nmib
	 * 
	 * @param nmia
	 *            First Neuron
	 * @param nmib
	 *            second Neuron
	 */
	public void connectTwoNeurons(int layer, String a, String b) {
		assert _neuronalnet != null : "Vorbedingung verletzt: _neuronalnet != null";
		_neuronalnet.setConnectionFromTo(layer,a, b);
		_neuronalnet.setWeigthFromTo(layer, a,b, 1);
	}
	
	
	public void setWeightOfTwoNeurons(int layer, String a, String b, double value) {
		assert _neuronalnet != null : "Vorbedingung verletzt: _neuronalnet != null";
		_neuronalnet.setWeigthFromTo(layer, a,b, value);
	}
	
	public double getWeightOfTwoNeurons(int layer, String a, String b) {
		assert _neuronalnet != null : "Vorbedingung verletzt: _neuronalnet != null";
		return _neuronalnet.getWeigthFromTo(layer, a,b);
	}

	/**
	 * Disconnect two Neurons of the Current Network
	 * 
	 * @param nmia
	 *            - Neuron One
	 * @param nmib
	 *            - Neuron Two
	 */
	public void disconnectTwoNeurons(int layer, String a, String b) {
		_neuronalnet.removeConnectionFromTo(layer,a,b);
		_neuronalnet.setWeigthFromTo(layer,a,b, 0);
	}

	/**
	 * Adds a Neuron to a Layer by the Reference of the Layer
	 * 
	 * @param nmi
	 *            - Neuron
	 * @param li
	 *            - Layer
	 */
	public void addNeuronToNetwork(int layer, String identifyer, String type) {
		_neuronalnet.addNeuron(layer, identifyer, type);
	}


	public boolean hasConnection(int layer,String nmia, String nmib) {
		return _neuronalnet.hasConnectionFromTo(layer,nmia, nmib);
	}
	
	public void raiseLayer(){
		_neuronalnet.raiseLayer();
	}

}
